﻿using Sitecore.Diagnostics;
using Sitecore.Shell.Framework.Commands;

namespace RedirectManager.Shell.Framework.Commands
{
    public class DeleteRedirect : Command
    {
        #region Overrides of Command

        public override void Execute(CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            if ((context.Items.Length == 1) && context.Items[0].Access.CanWrite())
            {
                context.Parameters.Add("id", context.Items[0].ID.ToString());
                Sitecore.Context.ClientPage.Start("uiDeleteRedirect", context.Parameters);
            }
        }

        public override CommandState QueryState(CommandContext context)
        {
            if (context.Items.Length == 1)
            {
                var contextItem = context.Items[0];
                if (contextItem.Paths.IsContentItem && contextItem.Access.CanWrite())
                {
                    return base.QueryState(context);
                }
            }

            return CommandState.Disabled;
        }
        #endregion
    }
}
